<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/Public/foundation/foundation.min.css">
    <link rel="stylesheet" href="/Public/foundation/jquery.datetimepicker.css">
    <script src="/Public/jquery/jquery.min.js"></script>
    <script src="/Public/foundation/foundation.min.js"></script>
    <script src="/Public/foundation/modernizr.js"></script>
    <script src="/Public/jquery/plugin/cityselect/jquery.cityselect.js"></script>

    <!--<script src="/Public/jquery/plugin"></script>-->
    <link rel="stylesheet" href="http://static.runoob.com/assets/foundation-icons/foundation-icons.css">
</head>
<body>
<nav class="top-bar" data-topbar>
    <ul class="title-area">
        <li class="name">
            <h1><a href="#">后台管理</a></h1>
        </li>
    </ul>
    <section class="top-bar-section">
        <ul class="right">
                <li><a href="">欢迎<?php echo (session('name')); ?></a></li>
                <li><a href="<?php echo U('./Sys/Login/doLogout');?>">退出</a></li>
        </ul>

    </section>
</nav>
<div>
    <div class="small-2 columns">
        <?php if(is_array($locks)): $i = 0; $__LIST__ = $locks;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$menu): $mod = ($i % 2 );++$i;?><ul class="side-nav">
                <li><a href="http://127.0.0.1/index.php/<?php echo ($menu["url"]); ?>" target="<?php echo ($menu['target']==0?'_self':'_blank'); ?>"><?php echo ($menu["mname"]); ?></a></li>
            </ul><?php endforeach; endif; else: echo "" ;endif; ?>
    </div>
    <div class="small-10 columns">
        
    <form action="?" method="get">
    <fieldset>
        <legend>字典查询</legend>
            <?php if(is_array($search)): $i = 0; $__LIST__ = $search;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$v): $mod = ($i % 2 );++$i;?><input type="checkbox" name="field" value="<?php echo ($v["field"]); ?>"><?php echo ($v["field"]); endforeach; endif; else: echo "" ;endif; ?>
            <input type="submit" class="button tiny edit" value="筛选">
        </fieldset>
    </form>

    <table id="dictsTbl">
    <thead>
    <tr>
        <th><input onclick="selectAll(this)" type="checkbox"></th>
        <th>编号</th>
        <th>字段名</th>
        <th>字段值</th>
        <th>字段描述</th>
        <th>是否作废</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
        <?php if(is_array($dict)): $i = 0; $__LIST__ = $dict;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$v): $mod = ($i % 2 );++$i;?><tr id="row_<?php echo ($v["dict_id"]); ?>">
                <td><input class="slct" type="checkbox" value="<?php echo ($v["dict_id"]); ?>"></td>
                <td><?php echo ($v["dict_id"]); ?></td>
                <td><input  name="field" type="text"  class="a" disabled value="<?php echo ($v["field"]); ?>"></td>
                <td><input  name="val" type="text" class="a" disabled value="<?php echo ($v["val"]); ?>"></td>
                <td><input name="desc" type="text" class="a" disabled value="<?php echo ($v["desc"]); ?>"></td>
                <td>
                    <div class="switch tiny">
                        <input onclick="lock(this)" value="<?php echo ($nav["dict_id"]); ?>" id="lock_<?php echo ($v["dict_id"]); ?>" type="checkbox" <?php echo ($nav['lock']?'checked':''); ?> >
                        <label for="lock_<?php echo ($v["dict_id"]); ?>"></label>
                    </div>
                </td>
                <td>
                    <button onclick="edit('row_<?php echo ($v["dict_id"]); ?>')" class="button tiny edit">编辑</button>
                    <button onclick="save('<?php echo ($v["dict_id"]); ?>')" style="display:none;" class="button tiny save">保存</button>
                </td>
            </tr><?php endforeach; endif; else: echo "" ;endif; ?>

    </tbody>
</table>
    <div>
        <span><?php echo ($page); ?></span>
    </div>
    <a class="button tiny" href="<?php echo U('addDict');?>">添加</a>
    <button onclick="unSelect()" class="button tiny">反选</button>
    <button onclick="delLot()" class="button tiny">删除(批量)</button>

    <script>
        //是否作废
        function lock(obj) {
            var id = $(obj).val();
            var lockval = $(obj).prop('checked')?1:0;
            $.post('<?php echo U("doEditDict");?>',{menu_id:id,lock:lockval});
        }
        //编辑
        function edit(rowid) {
            $('#'+rowid+' .a').prop('disabled',false);
            $('#'+rowid+' .edit').hide();
            $('#'+rowid+' .save').show();
           // console.log('#'+rowid);exit;
        }
        //保存
        function save(id) {
            $('#row_'+id+' .a').prop('disabled',true);
            $('#row_'+id+' .edit').show();
            $('#row_'+id+' .save').hide();

            var data = {
                dict_id:id,
                field:$('#row_'+id+' [name=field]').val(),
                val:$('#row_'+id+' [name=val]').val(),
                desc:$('#row_'+id+' [name=desc]').val(),
            }

            $.post('<?php echo U("doEditDict");?>',data,function (data) {
                if(data.error!==0){
                    alert(data.msg);
                }
            });
        }
        //全选
        function selectAll(obj) {
            $('#dictsTbl tbody .slct').prop('checked',$(obj).prop('checked'));
        }
        //反选
        function unSelect() {
            $('#dictsTbl tbody .slct').map(function(){
                $(this).prop('checked',!$(this).prop('checked'));
            });
        }
        //批量删除
        function delLot() {
            if(!confirm('确认批量删除吗')){
                return;
            }
            var ids = $('#dictsTbl tbody .slct:checked').map(function () {
                $(this).parent().parent().remove();
                return $(this).val();
            });
            ids  = ids.get().join();
            $.post('<?php echo U("doDelDict");?>',{ids:ids},function (data) {
                alert(data.msg);
            });
        }
    </script>

    </div>
</div>
</body>
</html>